﻿using AVIS.OutBound.AWD;
using AVIS.OutBound.Cities;
using AVIS.OutBound.Contents;
using AVIS.OutBound.Web.Models;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace AVIS.OutBound.Web.Controllers
{
    public class HomeController : OutBoundControllerBase
    {
        private readonly ICityAppService _cityAppService;
        private readonly IContentAppService _ContentAppService;
        private readonly IAWDAppService _AWDAppService;


        public HomeController(ICityAppService cityAppService,
            IContentAppService _contentAppService,
            IAWDAppService _aWDAppService)
        {
            _cityAppService = cityAppService;
            _ContentAppService = _contentAppService;
            _AWDAppService = _aWDAppService;

        }

        public ActionResult Index()
        {
            return Redirect("~/swagger");
            //return View();
        }

        public JsonResult GetHotCity()
        {
            var data = _cityAppService.GetHotCity();
            return Json(data, JsonRequestBehavior.AllowGet);
        }


        //public JsonResult GetHotCity()
        //{
        //    var data = _cityAppService.GetHotCity();
        //    List<HotCityViewModel> list = new List<HotCityViewModel>();

        //    var hotCities = from c in data
        //                    where c.IsHot.Value
        //                    orderby c.ClickCount descending, c.CNPY
        //                    select new HotsubCity
        //                    {
        //                        CNName=c.CNName,
        //                        CNPY=c.CNPY,
        //                        ENName=c.ENName,
        //                        IsHot= c.IsRed == true ? "1" : "0",
        //                        RegionCode=c.RegionCode,
        //                        CNSinple=c.CNSinple

        //                    };
        //    list.Add(new HotCityViewModel { ContinentName = "国际热门", list = hotCities.ToList() });
        //    // 各大洲的热门城市
        //    var ContinentCNNames = data.OrderBy(c => c.ContinentSeqNo).Select(c => c.ContinentASCNName).Distinct();
        //    foreach (var ContinentCNName in ContinentCNNames)
        //    {
        //        var subCities = from c in data
        //                        where c.ContinentASCNName == ContinentCNName
        //                        orderby c.ClickCount descending, c.CNPY
        //                        select new HotsubCity
        //                        {
        //                            CNName = c.CNName,
        //                            CNPY = c.CNPY,
        //                            ENName = c.ENName,
        //                            IsHot = c.IsRed == true ? "1" : "0",
        //                            RegionCode = c.RegionCode,
        //                            CNSinple = c.CNSinple
        //                        };
        //        list.Add(new HotCityViewModel { ContinentName = ContinentCNName, list = subCities.ToList() });
        //    }

        //    return Json(list, JsonRequestBehavior.AllowGet);
        //}

        /// <summary>
        /// 获取首页banner
        /// </summary>
        /// <returns></returns>
        //public JsonResult GetBanner()
        //{
        //    var data = _ContentAppService.GetBanner();
        //    return Json(data, JsonRequestBehavior.AllowGet);
        //}

        /// <summary>
        /// 获取特惠
        /// </summary>
        /// <returns></returns>
        //public JsonResult GetPromotion()
        //{
        //    var data = _ContentAppService.GetPromotion();
        //    //var Promotion = from c in data
        //    //                select new PromotionViewModel
        //    //                {
        //    //                    //PublishDate = c.PublishDate.ToString("yyyy/MM/dd HH:mm"),
        //    //                    //CatalogId=c.CatalogId,
        //    //                    Title=c.Title,
        //    //                    ThumbImageUrl=c.ThumbImageUrl,
        //    //                    //StartDate=c.StartDate.ToString("yyyy/MM/dd HH:mm"),
        //    //                    //EndDate=c.EndDate.ToString("yyyy/MM/dd HH:mm"),
        //    //                    //Summary=c.Summary,
        //    //                    //Content=c.Content,
        //    //                    QueryString=c.QueryString,
        //    //                    //LinkImage=c.LinkImage,
        //    //                    //ModifyDate=c.ModifyDate.ToString("yyyy/MM/dd HH:mm"),
        //    //                    //Type=c.Type     
        //    //                };
        //    return Json(data, JsonRequestBehavior.AllowGet);
        //}


        /// <summary>
        /// 校验AWD是否需要验证密码
        /// </summary>
        /// <param name="awdCode"></param>
        /// <returns></returns>
        //public JsonResult NeedCheckAWD(string awdCode)
        //{
        //    var data = _AWDAppService.GetAWDNumber(awdCode);
        //    if (data != null && !string.IsNullOrWhiteSpace(data.AWDPassWord))
        //    {
        //        return Json(new { result = true, prompt = data.Remark },JsonRequestBehavior.AllowGet);

        //    }
        //    else
        //    {
        //        return Json(new { result = true }, JsonRequestBehavior.AllowGet);

        //    }
        //}


        ///// <summary>
        ///// 校验AWD
        ///// </summary>
        ///// <param name="awdCode"></param>
        ///// <param name="password"></param>
        ///// <returns></returns>
        //public JsonResult CheckAWD(string awdCode, string password)
        //{
        //    var result = _AWDAppService.CheckAWD(awdCode, password);
        //    return Json(new { result = result }, JsonRequestBehavior.AllowGet);

        //}



    }
}